<?php
if(!isset($MAIN)){
	include_once("includes/class.ibnfm.php");
	$MAIN = new MAIN();
}
$MAIN->users->checkLogin(true);

if(isset($_REQUEST['del'])){
	$sql="delete from `".tblPrefix."memberof` where `id`=".$_REQUEST['del'];
	if($MAIN->executeCommand($sql)){
		?>
		<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');(function(){document.location.href='index.php?cat=memberof';}).delay(3000);</script>
		<?php
	}
}

if(isset($_REQUEST['txt_member_of'])){
	$sql="select * from `".tblPrefix."memberof` where `".tblPrefix."memberof`.`name`='".$_REQUEST['txt_member_of']."'";		
	$res=$MAIN->returnArray($sql);	
	if(count($res)>0){
		?>
		<script type="text/javascript">sendInfo(null,'Redan i databasen!');$('txt_memberof').value='';</script>
		<?php
	}else{
		$sql="insert into `".tblPrefix."memberof` (`name`) value ('".$_REQUEST['txt_member_of']."')";
		$MAIN->executeCommand($sql);
		?>
		<script type="text/javascript">sendInfo(null,'Dina ändringar har sparats!');(function(){document.location.href='index.php?cat=memberof';}).delay(3000);</script>
		<?php
	}
	exit();
}
?>
<div class="activ">
	<h2>Medlem av lista</h2>
	<form style="width:220px;" name="frm_member_of" acion="member_of.php" method="post">
		<input type="text" name="txt_member_of" id="txt_member_of" value=""/>&nbsp;&nbsp;<img style="cursor:pointer; margin-bottom:-3px;" onclick="ajaxGet('memberof.php','txt_member_of='+$('txt_member_of').value);" src="images/btn_add.png" title="Add" title="Add"/>
		<div>
			<?php			
			$membersof=$MAIN->returnArray("select * from `".tblPrefix."memberof`");			
			foreach($membersof as $m){
			?>
			<div><?php echo($m['name']);?>&nbsp;&nbsp;<img style="float:right; margin-right:7px;" src="images/btn_admin_del.png" title="Ta bort" title="Ta bort" onclick="ajaxGet('memberof.php','del=<?php echo($m['id']);?>');"/></div>
			<?php
			}
			?>
		</div>
	</form>
</div>